﻿package com.cb.model.objectmodels
{
	/**
	 * @author blackcj.com - Christopher Black - September 13, 2010
	 * 
	 * Resources: 
	 * http://www.emanueleferonato.com/2009/05/18/understanding-how-box2d-manages-boundaries/
	 * http://www.box2d.org/manual.html
	 * http://box2dflash.sourceforge.net/
	 *
	 */
	 
	import flash.events.EventDispatcher;
	import com.cb.model.vo.Object2dVO;
	import com.cb.view.objectviews.Circle2DView;
	import flash.geom.Rectangle;
	import com.cb.Constants;
	import flash.display.Sprite;
	import Box2D.Collision.*;
	import Box2D.Collision.Shapes.*;
	import Box2D.Common.Math.*;
	import Box2D.Dynamics.*;
	import com.cb.model.WorldModel;
	import com.cb.view.objectviews.Frame2DView;
		
	public class Frame2DModel extends EventDispatcher
	{
		private var _frame2DView:Frame2DView;
		private var _wallData:Array;
		private var _walls:Array;
		private var margin:int = 5;
		private var boxRect:Rectangle = new Rectangle(47,19.5,95,39);
		
		public function Frame2DModel(box_width:int, box_height:int)
		{		
			_frame2DView = new Frame2DView();
			
			_wallData = new Array();
			// Top wall
			_wallData.push(new Rectangle(box_width / 2, margin / 2, box_width, margin));
			
			// Bottom wall
			_wallData.push(new Rectangle(box_width/ 2, box_height - margin / 2, box_width, margin));
			
			// Left wall
			_wallData.push(new Rectangle(margin / 2, box_height / 2, margin, box_height));
			
			// Right wall
			_wallData.push(new Rectangle(box_width - margin / 2, box_height / 2, margin, box_height));
			
			buildWalls();

		}
		
		public function buildWalls():void
		{
			for(var n:int = 0; n < _wallData.length; n++){
				var wall2DModel:Wall2DModel = new Wall2DModel(_wallData[n]);
				_frame2DView.addChild(wall2DModel.wall2dView);
			}			
		}
		
		public function get frame2DView():Frame2DView
		{
			return _frame2DView;
		}
	}
}